package com.xmu.edu.tisp.synchronous;
//utils class for synchronous module
//By Chenb 2011-08-06

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;

import android.database.Cursor;

import com.xmu.edu.tisp.database.BaseService;
import com.xmu.edu.tisp.database.Tables;

public class Utils {
	
	public static String getCurrentTime(){
		Calendar calendar = Calendar.getInstance();
		long unixTime = calendar.getTimeInMillis();
		long unixTimeGMT = unixTime - TimeZone.getDefault().getRawOffset();
		SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		Date date = new Date(unixTimeGMT);
		String getTime = timeFormat.format(date);
		return getTime;
	}
	
	public static String getLastTime(String module){
		
		String col="DT_EXCHANGE_DATE";
		Cursor c=BaseService.getdb().query(Tables.TB_DATA_CXCHANGE, new String[]{col},
		"DT_EXCHANGE_FUNC=?", new String[]{module}, null, null,col);
		if(c.moveToLast()){
			return c.getString(0);
		}
		else{
			return "";
		}
	}
	
	//to string like  a,b,c
	public static String join(List<String> list,String separator){
		StringBuilder sb=new StringBuilder();
		int k=list.size();
		for(int i=0;i<k-1;++i){
			sb.append(list.get(i)+separator);
		}
		if(k>0){
			sb.append(list.get(k-1));
		}
		return sb.toString();
	}
	
	//get the current tabaccotechId,to be implemented
	public static String getTabaccoTechID(){
		return "tabaccoid";
	}
	
}
